//
//  DAFindBookTableViewCell.m
//  DAKnowledge
//
//  Created by DreamArts on 16/6/1.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAFindBookTableViewCell.h"
#import "DASearchBookModel.h"
#import "DALabel.h"
#import "DARateView.h"
#import "UIImageView+WebCache.h"
#import "Utility.h"

@interface DAFindBookTableViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *bookImage;
@property (weak, nonatomic) IBOutlet DALabel *bookName;
@property (weak, nonatomic) IBOutlet DARateView *rateView;
@property (weak, nonatomic) IBOutlet DALabel *bookSource;

@property (weak, nonatomic) IBOutlet DALabel *bookType;


@end
@implementation DAFindBookTableViewCell

- (void)awakeFromNib {
    // Initialization code
}




- (void)setSearchModel:(DASearchBookModel *)searchModel{
    if (_searchModel !=  searchModel) {
        _searchModel = searchModel;
    }
    
    
    UIView *bookCover = [[UIView alloc]initWithFrame:CGRectMake(0 , 0, self.bookImage.frame.size.width, self.bookImage.frame.size.height)];
    bookCover.backgroundColor = [UIColor supportGreenColor];
    DALabel *bookCoverName = [[DALabel alloc]initWithFrame:CGRectMake(5, 5, bookCover.frame.size.width -10, bookCover.frame.size.height - 10)];
    [bookCoverName setText:searchModel.bookName fitToContent:YES];
    [bookCoverName setTextColor:[UIColor whiteColor]];
    bookCoverName.font = [UIFont systemFontOfSize:12];
    bookCoverName.verticalAlignment = VerticalAlignmentMiddle;
    bookCoverName.textAlignment = NSTextAlignmentCenter;
    [bookCover addSubview:bookCoverName];
    
    UIImage *image = [self makeImageWithView:bookCover];
    [self.bookImage sd_setImageWithURL:[NSURL URLWithString:searchModel.bookImage] placeholderImage:image];
    
   // [self.bookImage sd_setImageWithURL:[NSURL URLWithString:searchModel.bookImage]];
    [self.bookName setText:searchModel.bookName fitToContent:YES];
    NSString *bookType = NSLocalizedString(@"bookType", nil);
    NSString *nothing = NSLocalizedString(@"Nothing", nil);
    NSString *type;
    if (searchModel.bookTypeName == nil) {
        type = [NSString stringWithFormat:@"%@: %@", bookType, nothing];
    }else{
        type = [NSString stringWithFormat:@"%@: %@", bookType,searchModel.bookTypeName];
    }
    [self.bookType setText:type fitToContent:YES];
    self.bookType.font = [UIFont systemFontOfSize:12];
    NSString *bookSourceStr = NSLocalizedString(@"bookSource", nil);
    NSString *bookSource;
    if (searchModel.bookSourceName == nil) {
        bookSource = [NSString stringWithFormat:@"%@: %@", bookSourceStr, nothing];
    }else{
        bookSource = [NSString stringWithFormat:@"%@: %@",bookSourceStr,searchModel.bookSourceName];
    }
    self.bookSource.font = [UIFont systemFontOfSize:12];
    [self.bookSource setText:bookSource fitToContent:YES];
    NSString *rateNum = searchModel.bookRate;
    [self.rateView rateNum:rateNum.integerValue];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
